{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn import  linear_model\n",
    "from sklearn import model_selection\n",
    "import statsmodels.api as sm\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "data1 = pd.read_excel(\"/Users/liuyang/Desktop/中科院/共享杯/气候小项目/广东各市用电量.xlsx\", sheet_name='1')\n",
    "data2 = pd.read_excel(\"/Users/liuyang/Desktop/中科院/共享杯/气候小项目/广东各市用电量.xlsx\", sheet_name='2')\n",
    "data3 = pd.read_excel(\"/Users/liuyang/Desktop/中科院/共享杯/气候小项目/广东各市用电量.xlsx\", sheet_name='3')\n",
    "data4 = pd.read_excel(\"/Users/liuyang/Desktop/中科院/共享杯/气候小项目/广东各市用电量.xlsx\", sheet_name='4')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "data1['汕头实际非工业（亿Kwh）']\n",
    "data1['影响因子1：GDP']\n",
    "data1['影响因子2：CDD']\n",
    "data1['影响因子3：HDD']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型的系数分别是：\n",
      " Intercept    4.884512\n",
      "GDP          0.003837\n",
      "CDD          0.010524\n",
      "HDD         -0.024321\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "model = sm.formula.ols('Y ~ GDP + CDD + HDD', data = data1).fit()\n",
    "print('汕头的模型的系数分别是：\\n', model.params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "东莞的模型的系数分别是：\n",
      " Intercept   -3.795830\n",
      "GDP          0.002616\n",
      "CDD          0.049648\n",
      "HDD         -0.017287\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "model = sm.formula.ols('Y ~ GDP + CDD + HDD', data = data2).fit()\n",
    "print('东莞的模型的系数分别是：\\n', model.params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "珠海的模型的系数分别是：\n",
      " Intercept    0.476186\n",
      "GDP          0.001725\n",
      "CDD          0.021855\n",
      "HDD         -0.003403\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "model = sm.formula.ols('Y ~ GDP + CDD + HDD', data = data3).fit()\n",
    "print('珠海的模型的系数分别是：\\n', model.params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州的模型的系数分别是：\n",
      " Intercept    5.616663\n",
      "GDP          0.001424\n",
      "CDD          0.137158\n",
      "HDD         -0.024598\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "model = sm.formula.ols('Y ~ GDP + CDD + HDD', data = data4).fit()\n",
    "print('广州的模型的系数分别是：\\n', model.params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
